package com.lkd.controller;

import com.lkd.dto.UserDto;
import com.lkd.entity.User;
import com.lkd.service.IUserService;
import com.lkd.vo.PageBean;
import com.lkd.vo.Result;
import com.lkd.vo.UserVo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: UserController
 * Package: com.lkd.controller
 * Description:
 *
 * @Author zt
 * @Create 2025/10/18 0:26
 * @Version 1.0
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/user-service/user")
public class UserController {
    private final IUserService userService;

    /**
     * 人员的分页搜索
     *
     * @param userDto
     * @return
     */
    @GetMapping("/search")
    public Result search(UserDto userDto) {
        PageBean<UserVo> pageBean = userService.search(userDto);
        return Result.success(pageBean);
    }

    /**
     * 新增人员
     */
    @PostMapping
    public Result saveUser(@RequestBody User user) {
        boolean save = userService.save(user);
        return Result.success(save);
    }

    /**
     * 修改人员
     */
    @PutMapping
    public Result updateUser(@RequestBody User user) {
        boolean updated = userService.updateById(user);
        return Result.success(updated);
    }

    /**
     * 删除人员
     */
    @DeleteMapping("/{userId}")
    public Result deleteUser(@PathVariable("userId") Integer id){
        boolean removed = userService.removeById(id);
        return Result.success(removed);
    }

}
